package fr.afcepf.atod21.brigade.daoImpl;

import java.util.List;

import javax.persistence.EntityManager;

import fr.afcepf.atod21.brigade.dao.BasicDaoImpl;
import fr.afcepf.atod21.brigade.entity.Intervention;

public class InterventionDaoJpa extends BasicDaoImpl<Intervention> {
	
	@SuppressWarnings("unchecked")
	public List<Intervention> findAllByReve(int idReve){
		return getEm().createQuery("select i from Intervention i where i.idReve = :paramIdReve").setParameter("paramIdReve",  idReve).getResultList();
	}

	@Override
	public void persist(Intervention anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		em.persist(anEntity);
		em.getTransaction().commit();
	}

	@Override
	public Intervention merge(Intervention anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		Intervention Intervention = em.merge(anEntity);
		em.getTransaction().commit();
		return Intervention;
	}

	@Override
	public void remove(Intervention anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		em.remove(anEntity);
		em.getTransaction().commit();
	}

	@Override
	public Intervention read(int id) {
		return (Intervention) getEm().createQuery("select i from Intervention i where i.idIntervention = :paramId").setParameter("paramId", id).getSingleResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Intervention> findAll() {
		return getEm().createQuery("select i from Intervention i").getResultList();
	}
}
